package br.com.comanda.util;

import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.util.Log;

/**
 * Classe para ajudar a manipulação de objetos para entrada/saída
 * 
 * @author thiago
 * @since 09/01/2013
 */
public final class IOUtils {

	private IOUtils() {
		super();
	}

	/**
	 * Fecha uma stream de saída
	 */
	public static void close(Closeable stream) {
		try {
			if (stream != null) {
				stream.close();
			}
		} catch (Exception ignored) {
			Log.e(Constantes.TAG_LOG, ignored.getMessage(), ignored);
		}
	}

	public static OutputStream open(String fileName) throws IOException {
		try {
			return new FileOutputStream(new File(fileName));
		} catch (FileNotFoundException e) {
			throw new IOException("Problema ao abrir stream de saida");
		}
	}

	public static OutputStream open(File file) throws IOException {
		try {
			return new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			throw new IOException("Problema ao abrir arquivo");
		}
	}
}
